<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/8/9
 * Time: 11:12
 */

namespace app\api\model;


use think\Model;

class ClassroomHistory extends Model
{
    /**
     * 查询课程观看历史
     * @param $user_id 用户ID
     * @param $classroom_id 课程ID
     * @param $field 查询字段
     * @return array|false|\PDOStatement|string|Model
     */
    public function getHistoryInfo($user_id, $classroom_id, $field){
        $historyInfo = $this->field($field)
            ->where('user_id', $user_id)
            ->where('classroom_id', $classroom_id)
            ->find();
        return $historyInfo;
    }
    
    /**
     * 如果是第一次观看，这插入历史
     * @param $data  插入的数据
     * @return false|int
     */
    public function createHistory($data){
        $res = $this->save($data);
        return $res;
    }
    
    /**
     * 如果有观看历史，则更新
     * @param $history_id  历史ID
     * @param $data 更新的数据
     * @return $this
     */
    public function updateHistory($history_id, $data){
        $res = $this->where('history_id', $history_id)->update($data);
        return $res;
    }
}